<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/view/conf/farmtag.tld" prefix="PF"%>
<c:if test="${USEROBJ==null}">
	<h1 style="color: #666; font-size: 24px; font-weight: 700;">
		<PF:ParameterValue key="config.sys.title" />
		用户注册
	</h1>
	<hr />
	<div class="form-signin" role="form" id="loginFormId" action="regist/reg.do" method="post">
		<div class="form-group">
			<label for="exampleInputEmail1"> 手机号 </label> <input type="text"
				class="form-control" placeholder="用户手机号"
				style="margin-top: 4px;" id="loginNameId" name="loginname" required
				autofocus>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1"> 登录密码 </label> <input type="password"
				class="form-control" placeholder="请录入密码" style="margin-top: 4px;"
				id="loginPassWId" name="password" required>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1"> 重复密码 </label> <input type="password"
																  class="form-control" placeholder="请录入密码" style="margin-top: 4px;"
																  id="loginPassWId2" required>
		</div>
		<%--<PF:IfParameterEquals key="config.sys.verifycode.able" val="true">
			<c:if test="${sessionScope.LOGINERRORNUM<=0}">
				<div class="form-group">
					<label for="exampleInputEmail1">验证码</label>
					<div class="input-group">
						<input type="text" class="form-control" placeholder="请录入验证码"
							id="checkcodeId" name="checkcode">
						<div class="input-group-addon" style="padding: 0px;">
							<img id="checkcodeimgId"
								style="cursor: pointer; height: 30px; width: 100px;"
								src="webfile/Pubcheckcode.do" />
						</div>
					</div>
				</div>
			</c:if>
		</PF:IfParameterEquals>--%>
		<!-- <input type="hidden" name="url" id="loginUrlId"> -->
		<div>
			<button class="btn btn-danger text-left" id="loginButtonId"
				style="margin-top: 4px; width: 100%;" type="button">注册</button>
		</div>
	</div>
	<c:if test="${STATE=='1'}">
		<div class="text-center" id="romovealertMessageErrorId"
			style="margin: 4px; color: red; border-top: 1px dashed #ccc; padding-top: 20px;">
			<span class="glyphicon glyphicon-exclamation-sign"></span> ${MESSAGE}
		</div>
	</c:if>
	<div class="text-center" id="alertMessageErrorId"
		style="margin: 4px; color: red; border-top: 1px dashed #ccc; padding-top: 20px;"></div>
</c:if>
<c:if test="${USEROBJ!=null}">
	<div>
		<div style="text-align: center;margin-top: 100px;margin-bottom: 50px;" >当前用户已登陆</div>
		<a class="btn btn-danger text-left" href="#"
			style="margin-top: 4px; width: 100%;" type="button">进入首页</a>
	</div>
</c:if>
<script type="text/javascript">
	$(function() {
		$('#alertMessageErrorId').hide();
		$('#loginButtonId')
				.bind('click', function() {
                    var loginname = $('#loginNameId').val();
                    if (!phoneFun(loginname)) {
                        showErrorMsg('请输入正确的手机号');
                        return;

                    }
                    var password = $('#loginPassWId').val();
                    if (loginname && password) {
                        if ($('#loginPassWId').val() != $('#loginPassWId2').val()) {
                            showErrorMsg('两次输入的密码不一致')
                            return;
                        }
                    } else {
                        showErrorMsg('请输入密码')
                        return;
                    }
					/*var scret_password = (AuthKeyProvider.encode(
							'${config_password_provider_type}', password));*/
					//$('#loginFormId').submit();
                    regUser({loginname, 'password': password})
				});
		/*$('#checkcodeimgId').bind(
				"click",
				function(e) {
					$('#checkcodeimgId').attr(
							"src",
							"webfile/Pubcheckcode.do?time="
									+ new Date().getTime());
				});
		$('#loginNameId').keydown(function(e) {
			if (e.keyCode == 13) {
				//$('#loginUrlId').val(window.location.href);
				$('#loginButtonId').click();
			}
		});
		$('#loginPassWId').keydown(function(e) {
			if (e.keyCode == 13) {
				//$('#loginUrlId').val(window.location.href);
				$('#loginButtonId').click();
			}
		});
		$('#checkcodeId').keydown(function(e) {
			if (e.keyCode == 13) {
				//$('#loginUrlId').val(window.location.href);
				$('#loginButtonId').click();
			}
		});*/
	});

    function regUser(user) {
        /*$.ajax({
            url: '/regist/reg.do',
            method: 'POST',
            data: user,
            complete: function (XHR, TS) {
				console.log(XHR)

				if (TS == 'success') {
                } else {
                    //console.log(XHR)
                }
            },
            dataType: 'json'
        })*/
		$.post('regist/reg.do', user, function(responseText) {
			var response = JSON.parse(responseText);
			if (response.STATE == '1') {
				showErrorMsg(response.MESSAGE)
			} else {
				showSuccessMsg('注册成功，请登录！')
				setTimeout(function () {
					location.href = '/login/PubLogin.do';
				}, 2000)
			}
		});
    }

	function showErrorMsg(msg) {
		$('#alertMessageErrorId').show();
		$('#romovealertMessageErrorId').hide();
		$('#alertMessageErrorId')
				.html('<span class="glyphicon glyphicon-exclamation-sign"></span>' + msg);
	}

	function showSuccessMsg(msg) {
		$('#alertMessageErrorId').show();
		$('#romovealertMessageErrorId').hide();
		$('#alertMessageErrorId')
				.html(msg);
	}

    //判断是否为手机号的正则表达式
    function phoneFun(phones){
        var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
        if (!myreg.test(phones)) {
            return false;
        } else {
            return true;
        }
    }
//-->
</script>